package com.dhj.yygh.controller;

import com.dhj.yygh.common.result.MyResult;
import com.dhj.yygh.model.hosp.Hospital;
import com.dhj.yygh.service.HospitalService;
import com.dhj.yygh.vo.hosp.HospitalQueryVo;
import com.dhj.yygh.vo.hosp.HospitalSetQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Slf4j
@Api(tags = "医院信息相关接口")
@RestController
@RequestMapping("/admin/hospital/hospitalmanager")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    @ApiOperation("医院信息分页")
    @GetMapping("/getHospitalPage/{page}/{pageCount}")
    public MyResult<Page<Hospital>> getHospitalPage(@PathVariable("page") Integer page,
                                                    @PathVariable("pageCount") Integer pageCount,
                                                    HospitalQueryVo hospitalQueryVo) {

        Page<Hospital> hospitalPage = hospitalService.selectHospitalPage(page - 1, pageCount, hospitalQueryVo);
        return MyResult.ok(hospitalPage);
    }

    @ApiOperation("更新医院的上线状态")
    @PutMapping("/updateHospitalStatusById/{id}/{status}")
    public MyResult updateHospitalStatus(
            @PathVariable("id") String id,
            @PathVariable("status") Integer status
    ) {
        Hospital hospital = hospitalService.updateHospitalStatus(id, status);

        return hospital.getStatus() == 1 ? MyResult.ok("以上线!") : MyResult.ok("以下线!");
    }

    @ApiOperation("根据 id 获取医院详情信息")
    @GetMapping("/getHospitalDetailsById/{id}")
    public MyResult<Map<String, Object>> getHospitalDetailsById(@PathVariable("id") String id) {

        Map<String, Object> map = hospitalService.getHospitalDetailsById(id);

        return MyResult.ok(map);
    }
}
